<?php 
use \PsiFramework\Classes\Util\UI\Printer;
use \PsiFramework\Classes\Util\UI\HTML;

$cities = $response->getAttribute("cities");
$countries = $response->getAttribute("countries");
$genders = $response->getAttribute("genders");
$sexualBehaviors = $response->getAttribute("sexualBehaviors");

$user = $response->getAttribute("user");
$action = $response->getAttribute("action");
$captcha = $response->getAttribute("captcha");
$error = $response->getAttribute("error");
$lang = $response->getAttribute("lang"); ;
$div = strtolower($action);
?>
<div id="<?php Printer::display($div); ?>">
    <?php
    if ($error != null) {
        ?>
    <div id="formError" class="error">
        <?php Printer::display($error);?>
    </div>
    <?php 
    }
    ?>
    <form
        class="editForm"
        action="<?php Printer::display(HTML::linkHref('action='.$action));?>"
        method="POST" enctype="multipart/form-data">
        <?php
        if ($action == "Register") {
        ?>
        <input
            type="hidden"
            name="redirectAction"
            value="Profile" />
        <span class="label oblig">
            <span class="titre">
                <?php Printer::display($languageManager->getText("LOGIN_NAME")); ?> : 
            </span>
            <input
                class="firstInput"
                type="text"
                name="login"
                id="loginBox"
                value="<?php if ($user!=null && $user->getLogin() != null) Printer::display($user->getLogin()); ?>"
                required="required" />
        </span>
        <span class="label oblig">
            <span class="titre">
                <?php Printer::display($languageManager->getText("PASSWORD")); ?> : 
            </span>
            <input
                type="password"
                name="password"
                class="firstinput checkEqual:confirmPasswordBox"
                id="passwordBox"
                value=""
                required="required" />
        </span>
        <span class="label oblig"> <span class="titre">
            <?php Printer::display($languageManager->getText("CONFIRM_PASSWORD")); ?> : 
        </span>
        <input
            class="firstInput"
            type="password"
            name="confirmPassword"
            id="confirmPasswordBox"
            value=""
            required="required" />
        </span>
        <?php
        }
        ?>
        <span class="label">
            <span class="titre">
                <?php Printer::display($languageManager->getText("PROFILE_PIC")); ?> :
            </span>
            <?php 
            $displayPicture = true ;
            if ($user != null && $user->getPicture() != null) {
            ?>
            <input
                type="hidden"
                name="oldPictureName"
                value="<?php Printer::display($user->getPicture()); ?>" />
            <img
                src="<?php Printer::display("Portal/Images/Profiles/Small/".$user->getPicture()); ?>"
                width="40px"
                height="40px" />
            <a href="javascript:showPictureBox();" id="changePicture">
                <?php Printer::display($languageManager->getText("CHANGE_PICTURE")); ?>
            </a>
            <?php
                $displayPicture = false ;
            }
            ?>
            <input
                class="firstInput"
                type="file"
                name="pictureName"
                id="pictureBox" 
                <?php if (!$displayPicture) echo 'style="display: none;"' ; ?> />
        </span>
        <span class="label oblig">
            <span class="titre">
                <?php Printer::display($languageManager->getText("EMAIL")); ?> : 
            </span>
            <input
                class="firstInput"
                type="email"
                name="email"
                id="emailBox"
                value="<?php if ($user!=null && $user->getEmail() != null) Printer::display($user->getEmail()); ?>"
                required="required" />
        </span>
        <span class="label">
            <span class="titre">
                <?php Printer::display($languageManager->getText("GENDER")); ?> : 
            </span>
            <select class="firstInput" name="gender" id="genderBox">
                <option value=""></option>
                <?php
                foreach ($genders as $gender) {
                ?>
                <option
                    value="<?php Printer::display($gender->getId()); ?>"
                    <?php
                    if (
                        $user!=null && $user->getGender() != null &&
                        $gender->getId() == $user->getGender()->getId()
                    ) {
                    ?>
                    selected="selected"
                    <?php
                    }
                    ?>
                    >
                    <?php Printer::display($languageManager->getText($gender->getName())); ?>
                </option>
                <?php
                }
                ?>
            </select>
        </span>
        <span class="label oblig">
            <span class="titre">
                <?php Printer::display($languageManager->getText("BIRTH")); ?> : 
            </span>
            <!-- <input type="date" name="birthDate" required="required" />  -->
            <select
                class="day"
                name="monthOfBirth"
                id="monthOfBirthBox"
                required="required">
                <option value=""></option>
                <?php
                for ($i=1; $i<=12; $i++) { 
                    if ($i<10) $i="0".$i ;
                ?>
                <option
                    value="<?php Printer::display($i); ?>"
                    <?php
                    if (
                        $user!=null && $user->getBirth() != null &&
                        $user->getBirth()->getMonth() == $i
                    ) {
                    ?>
                    selected="selected"
                    <?php
                    }
                    ?>
                    >
                    <?php Printer::display($i); ?>
                </option>
                <?php
                }
                ?>
            </select>
             - 
            <select
                class="month"
                name="dayOfBirth"
                id="dayOfBirthBox"
                required="required">
                <option value=""></option>
                <?php
                for ($i=1; $i<=31; $i++) { 
                    if ($i<10) $i="0".$i ;
                ?>
                <option
                    value="<?php Printer::display($i); ?>"
                    <?php
                    if (
                        $user!=null && $user->getBirth() != null &&
                        $user->getBirth()->getDay() == $i
                    ) {
                    ?>
                    selected="selected"
                    <?php
                    }
                    ?>
                    >
                    <?php Printer::display($i); ?>
                </option>
                <?php
                }
                ?>
            </select>
             - 
            <select class="year" name="yearOfBirth"
            id="yearOfBirthBox" required="required">
                <option value=""></option>
                <?php
                $date = getDate();
                $year = $date['year'] ;
                for ($i=$year; $i>=1900; $i--) {
                ?>
                <option
                    value="<?php Printer::display($i); ?>"
                    <?php
                    if (
                        $user!=null && $user->getBirth() != null &&
                        $user->getBirth()->getYear() == $i
                    ) {
                    ?>
                    selected="selected"
                    <?php
                    }
                    ?>
                    >
                    <?php Printer::display($i); ?>
                </option>
                <?php
                }
                ?>
            </select>
        </span>
        <span class="label">
            <span class="titre">
                <?php Printer::display($languageManager->getText("COUNTRY")); ?> : 
            </span>
            <select
                class="firstInput"
                name="country"
                id="countryBox"
                onchange="javascript:displayCities();">
                <option value=""></option>
                <?php 
                if ($countries != null) {
                    foreach ($countries as $country) {
                ?>
                <option
                    value="<?php Printer::display($country->getISO()); ?>"
                    <?php
                        if (
                            $user != null &&
                            $user->getCity()!=null &&
                            $user->getCity()->getSubdivision() != null &&
                            $user->getCity()->getSubdivision()->getCountry()->getISO()==$country->getISO()
                        ) {
                    ?>
                    selected="selected"
                    <?php
                        }
                    ?>
                    >
                    <?php Printer::display($country->getName()); ?>
                </option>
                <?php
                    }
                }
                ?>
            </select>
        </span>
        <span class="label">
            <span class="titre">
                <?php Printer::display($languageManager->getText("CITY")); ?> : 
            </span>
            <select class="firstInput" name="city" id="cityBox">
                <option value=""></option>
                <?php 
                if ($cities != null) {
                    foreach ($cities as $city) {
                ?>
                <option
                    value="<?php Printer::display($city->getId()); ?>"
                    <?php
                        if (
                            $user != null &&
                            $user->getCity()!=null &&
                            $user->getCity()->getId()==$city->getId()
                        ) {
                    ?>
                    selected="selected"
                    <?php
                        }
                    ?>
                    >
                    <?php Printer::display($city->getName()); ?>
                </option>
                <?php
                    }
                }
                ?>
            </select>
        </span>
        <span class="label">
            <span class="titre">
                <?php Printer::display($languageManager->getText("PERSONAL_INFORMATION")); ?> : 
            </span>
            <textarea class="firstInput" name="text" id="textBox"><?php
                if ($user!=null && $user->getText() != null) Printer::display($user->getText());
            ?></textarea>
        </span>
        <?php
        if ($captcha != null) $captcha->showCaptchaCode($lang);
        ?>
        <input
            type="submit"
            value="<?php Printer::display($languageManager->getText("SUBMIT")); ?>"
            />
    </form>
</div>
